﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;

namespace GiveGraphModel
{
    public class ProductDonation
    {
        public Member Member { get; set; }
        public Product Product { get; set; }
        public Organization Organization { get; set; }
        internal int MemberId { get; set; }
        internal int ProductId { get; set; }
        internal int OrganizationId { get; set; }
    }

    public sealed class ProductDonationConfiguration : EntityTypeConfiguration<ProductDonation>
    {
        public ProductDonationConfiguration()
        {
            HasRequired(pd => pd.Member)
                .WithMany()
                .HasForeignKey(pd => pd.MemberId)
                .WillCascadeOnDelete(false);

            HasRequired(pd => pd.Organization)
                .WithMany()
                .HasForeignKey(pd => pd.OrganizationId)
                .WillCascadeOnDelete(false);

            HasRequired(pd => pd.Product)
                .WithMany()
                .HasForeignKey(pd => pd.ProductId)
                .WillCascadeOnDelete(false);

            HasKey(pd => new { pd.MemberId, pd.OrganizationId, pd.ProductId });
        }
    }
}
